<include file="../Public/_header" />
<div class="so_main">
  
  <div class="page_tit">分类管理</div>
  <div class="Toolbar_inbox">
	<a href="{:U('admin/Content/addAc')}" class="btn_a""><span>添加分类</span></a>
    <a href="javascript:void(0);" class="btn_a" onclick="deleteAc();"><span>删除分类</span></a>
  </div>
  <div class="list">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th style="width:30px;">
        <input type="checkbox" id="checkbox_handle" onclick="checkAll(this)" value="0">
        <label for="checkbox"></label>
    </th>
    <th class="line_l">ID</th> <th class="line_l">标题</th>
    
    <th class="line_l">子类</th>
    
    <th class="line_l">创建时间</th>
    
    <th class="line_l">排序</th>
    <th class="line_l">操作</th>
  </tr>
  <volist id="vo" name="ac">
      <tr overstyle='on' id="{$vo.ac_id}">
        <td><input type="checkbox" name="checkbox" id="checkbox2" onclick="checkon(this)" value="{$vo.ac_id}"></td>
        <td>{$vo.ac_id}</td>
        <td>{$vo.title}</td>
        <td>{$vo.ac_id|getBcCount}</td>
        <td>{$vo.ctime|date="Y-m-d H:i",###}</td>
   
        <td>
            <a href="javascript:void(0)" class="ico_top" onclick="move('{$vo['ac_id']}','up');"><img src="__PUBLIC__/admin/images/zw_img.gif"></a>&nbsp;&nbsp;
            <a href="javascript:void(0)" class="ico_btm" onclick="move('{$vo['ac_id']}','down');"><img src="__PUBLIC__/admin/images/zw_img.gif"></a>
        </td>
        <td>
			<a href="{:U('admin/Content/editAc',array('id'=>$vo['ac_id']))}">编辑</a>
			<a href="javascript:void(0);" onclick="deleteAc('{$vo.ac_id}')">删除</a>
		</td>
      </tr>
  </volist>
  </table>
  </div>
  <div class="Toolbar_inbox">
	<a href="{:U('admin/Content/addAc')}" class="btn_a""><span>添加分类</span></a>
    <a href="javascript:void(0);" class="btn_a" onclick="deleteAc();"><span>删除分类</span></a>
  </div>
</div>

<script>
    //鼠标移动表格效果
    $(document).ready(function(){
        $("tr[overstyle='on']").hover(
          function () {
            $(this).addClass("bg_hover");
          },
          function () {
            $(this).removeClass("bg_hover");
          }
        );
    });
    
    function checkon(o){
        if( o.checked == true ){
            $(o).parents('tr').addClass('bg_on') ;
        }else{
            $(o).parents('tr').removeClass('bg_on') ;
        }
    }
    
    function checkAll(o){
        if( o.checked == true ){
            $('input[name="checkbox"]').attr('checked','true');
            $('tr[overstyle="on"]').addClass("bg_on");
        }else{
            $('input[name="checkbox"]').removeAttr('checked');
            $('tr[overstyle="on"]').removeClass("bg_on");
        }
    }

    //获取已选择用户的ID数组
    function getChecked() {
        var ids = new Array();
        $.each($('table input:checked'), function(i, n){
            ids.push( $(n).val() );
        });
        return ids;
    }
    
 
    
    function deleteAc(ids) {
    	var length = 0;
    	if(ids) {
    		length = 1;
    	}else {
    		ids    = getChecked();
    		length = ids[0] == 0 ? ids.length - 1 : ids.length;
            ids    = ids.toString();
    	}
    	if(ids=='') {
    		ui.error('请先选择一个分类');
    		return ;
    	}
    	if(confirm('您将删除'+length+'条记录，删除后无法恢复，确定继续？')) {
    		$.post("{:U('admin/Content/doDeleteAc')}",{ids:ids},function(res){
    			if(res=='1') {
    				ui.success('删除成功');
    				removeItem(ids);
    			}else if(res=='2'){
    				ui.error('有子类无法删除');
    			}else {
    				ui.error('删除失败');
    			}
    		});
    	}
    }
    
    function removeItem(ids) {
    	ids = ids.split(',');
        for(i = 0; i < ids.length; i++) {
            $('#'+ids[i]).remove();
        }
    }

	function move(ac_id, direction) {
		var baseid  = direction == 'up' ? $('#'+ac_id).prev().attr('id') : $('#'+ac_id).next().attr('id');
		if(!baseid) {
			direction == 'up' ? ui.error('已经是最前面了') : ui.error('已经是最后面了');
		}else {
			$.post("{:U('admin/Content/doAcOrder')}", {ac_id:ac_id, baseid:baseid}, function(res){
				if(res == '1') {
					//交换位置
					direction == 'up' ? $('#'+ac_id).insertBefore('#'+baseid) : $("#"+ac_id).insertAfter('#'+baseid);
					ui.success('保存成功');
				}else {
					ui.error('保存失败');
				}
			});
		}
	}
</script>
<include file="../Public/_footer" />